package com.NetWork.lesson3;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

//事实上，不需要服务器，但是需要接收发来的文件
//且一直等待客户端的连接
public class UdpServer {
    public static void main(String[] args) throws Exception {
        //开放端口
        DatagramSocket socket = new DatagramSocket(9090);
        //接受数据包
        byte[] buffer = new byte[1024];
        DatagramPacket packet = new DatagramPacket(buffer, 0, buffer.length);//接受

        socket.receive(packet);//阻塞接收

        System.out.println(packet.getAddress().getHostAddress());
        System.out.println(new String(packet.getData(),0,packet.getLength()));

        //关闭连接
        socket.close();

    }
}

    